﻿@model IEnumerable<TelerikConnect.Web.ViewModels.MessagePreviewViewModel>
@using Kendo.Mvc.UI

@{
    ViewBag.Title = "Messages";
}
<div class="content-wrapper">
    <h2>Sent Messages</h2>
    <span id="send-message" class="k-button">Send New Message</span>

    @(Html.Kendo().Grid<TelerikConnect.Web.ViewModels.MessagePreviewViewModel>()
    .Name("grid")
            //.HtmlAttributes(new { style = "width: 750px;height:430px;" })
    .Columns(columns =>
    {
        columns.Bound(t => t.Sender.UserName).Title("Sender");
        columns.Bound(t => t.Title).Title("Message");
        columns.Bound(t => t.SentTime).Title("Delivered At").Format("{0:dd/MM/yyyy}");
    })
    .Sortable(sortable => sortable.AllowUnsort(false))
    .ClientRowTemplate(
        "<tr role='row' class='k-alt'>" +
            "<td role='gridcell'>" +
               "<img src='#:data.Sender.Avatar#' class='thumb-img' />" +
               "<a href='" + Url.Content("~/Account/Profile/") + "#:data.Sender.UserName#' class='k-button'>#:data.Sender.UserName#</a>" +
            "</td>" +
            "<td role='gridcell'>" +
            "<a href='" + Url.Content("~/Messages/Preview/") + "#:data.Id#' >#:data.Title#</a>" +
            "</td>" +
            "<td role='gridcell'>" +
            "<span>#:data.SentTime#</span>" +
            "</td>" +
         "</tr>"
    )
    .DataSource(dataSource => dataSource
        .Ajax()
        .Sort(sort => sort.Add("SentTime").Descending())
        .Read(read => read.Action("GetSent", "Messages"))
    )
    .Sortable()
    .Scrollable()
    .Pageable()
)

</div>

<script>
    $("#send-message").click(function () {
        var data = '<iframe frameborder = "0" width="480" height="350" src="/Messages/Send" ></iframe>';
        var kendoWindow = $("#window").data("kendoWindow");
        kendoWindow.content(data);

        kendoWindow.center();
        kendoWindow.open();
    });
</script>
